using TMPro;
using UnityEngine;

public class GoldView : MonoBehaviour
{
    [SerializeField] private TMP_Text goldTMP;
    private int _goldNumber;

    public int GoldNumber
    {
        get => _goldNumber;
        set
        {
            Debug.Log($"金币值变化: 旧值={_goldNumber}，新值={value}，调用栈={new System.Diagnostics.StackTrace()}");
            _goldNumber = value;
            UpdateGoldText();
        }
    }

    private void Awake()
    {
        GoldNumber = InfoSystem.Instance.hero.Gold;
    }

    private void UpdateGoldText()
    {
        goldTMP.text = _goldNumber.ToString();
        InfoSystem.Instance.hero.Gold = _goldNumber;
    }

    // 可以添加一个公共方法用于外部更新金币数量
    public void SetGold(int newGoldAmount)
    {
        GoldNumber = newGoldAmount;
    }
}